import {message} from "antd";
import {ReactElement, useEffect} from "react";
import {getToken} from "@/utils/token.ts";
import {useNavigate} from "react-router-dom";

interface Props {
    children: ReactElement;
}
// 鉴权路由
const PrivateRoute = ({children}: Props) => {
    const navigator = useNavigate();

    useEffect(() => {
        try {
            const token: any = getToken();
            if (!token) {
                message.warning("token过期,请重新登录");
                navigator(`/login`);
            }
        } catch (error) {
            message.warning("token过期,请重新登录");
            navigator(`/login`);
        }
    }, []);

    return <>{children} </>;
};

export default PrivateRoute;